home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DDJ0992.ARJ / DBSUPT.ASM < prev    next >
Assembly Source File  |  1992-05-31  |  9KB  |  241 lines

  1. ;dbsupt.asm 
  2. ;Miscellaneous support routines for debugger 
  3. ;
  4. .386P
  5. ;---------------------------------------------------------------------------- 
  6. ;Copyright 1991, 1992 ASMicro Co. 
  7. ;7/6/91       Rick Knoblaugh
  8. ;-----------------------------------------------------------------------------
  9.                 include dbequ.inc
  10.                 include dbstruc.inc
  11.  
  12. data            segment para public 'data16' use16
  13. data            ends
  14.  
  15. zcode    segment para public 'code16' use16
  16.  
  17.                 public  convert_upper, convert_2_linear, must_be_hex     
  18.                 public  format_seg, put_hex_byte, put_nibble, get_validate               
  19.                 public  hex2bin, skip_white_sp, put_hex_word
  20.  
  21.     assume cs:zcode, ds:data, es:nothing
  22.  
  23.  
  24. ;----------------------------------------------------------------------
  25. ; convert_upper - convert string to upper case.                       |
  26. ;                                                                     |
  27. ;             Enter: si = offset of start of string                   |
  28. ;                    cx = string length                               |
  29. ;                                                                     |
  30. ;        All registers saved.                                         |
  31. ;----------------------------------------------------------------------
  32. convert_upper   proc    near
  33.                 jcxz    convert_u999
  34.                 push    cx
  35.                 push    si
  36. convert_u100:
  37.                 cmp     byte ptr [si], 'a'
  38.                 jb      short convert_u500
  39.                 and     byte ptr [si], 0dfh
  40. convert_u500:
  41.                 inc     si
  42.                 loop    convert_u100
  43.                 pop     si
  44.                 pop     cx
  45. convert_u999:
  46.                 ret
  47. convert_upper   endp        
  48.  
  49. convert_2_linear proc   near
  50.                 movzx   edx, dx
  51.                 shl     edx, 4
  52.                 movzx   ebx, bx
  53.                 add     edx, ebx
  54.                 ret
  55. convert_2_linear endp
  56.  
  57.  
  58. ;--------------------------------------------------------------
  59. ;must_be_hex - Test char in al for hex range.                 |
  60. ;                                                             |
  61. ;               Enter: al = char to test.                     |
  62. ;                Exit: carry flag set if al not an ASCII hex  |
  63. ;                      digit.                                 |
  64. ;--------------------------------------------------------------
  65. must_be_hex     proc    near
  66.                 push    ax
  67.                 cmp     al, 'a'
  68.                 jb      short must_b100
  69.                 and     al, 0dfh                ;force to uppercase
  70. must_b100:
  71.                 cmp     al, '0'
  72.                 jb      short must_b800
  73.                 cmp     al, '9'                 ;see if 0-9 or A-F
  74.                 jbe     short must_b600
  75.  
  76.                 cmp     al, 'A'
  77.                 jb      short must_b800
  78.                 cmp     al, 'F'
  79.                 ja      short must_b800
  80. must_b600:
  81.                 clc
  82.                 jmp     short must_b900
  83. must_b800:
  84.                 stc
  85. must_b900:
  86.                 pop     ax
  87.                 ret
  88. must_be_hex     endp
  89.  
  90. ;--------------------------------------------------------------
  91. ;format_seg - format segment and offset in ds:si in ASCII     |
  92. ;             as follows:                                     |
  93. ;                          xxxx:xxxx                          |
  94. ;             Put into buffer from ptr es:di                  |
  95. ;                                                             |
  96. ;             Exit: di = next offset in output buffer.        |
  97. ;--------------------------------------------------------------
  98.  
  99. format_seg      proc    near
  100.                 mov     ax, ds                  ;do the segment
  101.                 call    put_hex_word
  102.                 mov     al, ':'
  103.                 stosb
  104.                 inc     di                      ;past attribute
  105.                 mov     ax, si                  ;do the offset
  106.                 call    put_hex_word
  107.                 ret
  108. format_seg      endp        
  109.  
  110.  
  111. put_hex_word:
  112.                 mov     dl, al                  ;save LSB
  113.                 mov     al, ah                  ;want to print MSB first        
  114.                 call    put_hex_byte
  115.                 mov     al, dl
  116.  
  117. put_hex_byte:                
  118.                 mov     ah, al
  119. put_hex_100:
  120.                 shr     al, 4                   ;get high portion
  121.                 call    put_nibble
  122.                 mov     al, ah
  123.                 and     al, 0fh      
  124. put_nibble:
  125.                 cmp     al, 9
  126.                 ja      short put_nib_100
  127.                 add     al, '0'
  128.                 jmp     short put_nib_300
  129. put_nib_100:
  130.                 add     al, 'A' - 10
  131. put_nib_300:
  132.                 stosb
  133.                 inc     di                      ;past attribute
  134.                 ret
  135.  
  136. ;--------------------------------------------------------------
  137. ;get_validate - Retrieve and validate an ASCII hex number.    |
  138. ;                                                             |
  139. ;              Enter: si = ptr to data                        |
  140. ;                     dl = max number of digits to get        |
  141. ;                     dh = if non zero, is a delimiter which  |
  142. ;                          may be at end of number (typically |
  143. ;                          ':' when retrieving a segment)     |
  144. ;                     cx = number of remaining chars in buffer|
  145. ;                                                             |
  146. ;               Exit: cx decremented by length of number      |
  147. ;                     si incremented past data                |
  148. ;                     ax=binary value of number               |
  149. ;                     If invalid, carry set                   |
  150. ;      bx saved                                               |
  151. ;--------------------------------------------------------------
  152. get_validate    proc    near
  153.                 push    bx
  154.                 xor     bx, bx
  155.  
  156.                 push    cx
  157.                 sub     ch, ch
  158.                 mov     cl, dl                  ;max digits to get
  159. get_v100:
  160.                 or      dh, dh                  ;may hit delimiter?
  161.                 jz      short get_v150          ;if not, skip
  162.                 cmp     byte ptr [si + bx], dh  ;hit delimiter?
  163.                 je      short get_v200          ;if so, look only up to it
  164. get_v150:
  165.                 cmp     byte ptr [si + bx], ' ' 
  166.                 je      short get_v200
  167.                 inc     bx
  168.                 loop    short get_v100
  169. get_v200:
  170.                 pop     cx
  171.                 sub     cx, bx                  ;chars left
  172.                 push    cx
  173.                 mov     cx, bx
  174.                 xor     bx, bx
  175. get_v300:
  176.                 sub     ah, ah
  177.                 lodsb                           ;get a digit
  178.                 call    hex2bin                 ;validate and convert
  179.                 jc      short get_v900          ;exit if invalid
  180.                 push    cx
  181.                 jcxz    get_v500
  182.                 dec     cx                      ;position from right - 1
  183.                 shl     cl, 2
  184.                 shl     ax, cl                  ;get nibble into position
  185. get_v500:
  186.                 or      bx, ax                  ;build number
  187.                 pop     cx
  188.                 loop    get_v300
  189.                 clc                             ;ok
  190.  
  191. get_v900:
  192.                 mov     ax, bx
  193.                 pop     cx
  194.                 pop     bx
  195.                 ret
  196. get_validate    endp        
  197.  
  198.  
  199.  
  200.  
  201. hex2bin         proc    near
  202.                 cmp     al, '0'
  203.                 jb      short hex2_800
  204.                 cmp     al, '9'                 ;see if 0-9 or A-F
  205.                 ja      short hex2_500
  206.                 sub     al, '0'                 ;convert to binary
  207.                 jmp     short hex2_600
  208. hex2_500:
  209.                 cmp     al, 'F'
  210.                 ja      short hex2_800
  211.                 sub     al, 'A' - 10
  212. hex2_600:
  213.                 clc
  214.                 ret
  215. hex2_800:
  216.                 stc
  217. hex2_900:
  218.                 ret
  219. hex2bin        endp        
  220.  
  221.  
  222.  
  223. skip_white_sp   proc    near
  224.                 jcxz    skip_w900
  225. skip_w100:
  226.                 cmp     byte ptr [si], ' '
  227.                 je      short skip_w200
  228.                 cmp     byte ptr [si], TAB
  229.                 jne     short skip_w900
  230.  
  231. skip_w200:
  232.                 inc     si
  233.                 loop    skip_w100     
  234. skip_w900:
  235.                 ret
  236. skip_white_sp   endp
  237.  
  238. zcode            ends
  239.             end          
  240.  
  241.